package com.tuangou.tuangouorder.order.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.atguigu.common.vo.OrderResultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tuangou.tuangouorder.order.dao.OrderDao;
import com.tuangou.tuangouorder.order.entity.OrderEntity;
import com.tuangou.tuangouorder.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),
                new QueryWrapper<OrderEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageInfo<OrderResultVo> mohu(Map<String, Object> params) {
        if(params.get("pageNum") == null){
            params.put("pageNum","1");
        }
        if(params.get("pageSize") == null){
            params.put("pageSize","3");
        }
        PageHelper.startPage(Integer.parseInt((String) params.get("pageNum")),Integer.parseInt((String) params.get("pageSize")));
        List<OrderResultVo> list = orderDao.mohu(params);
        PageInfo<OrderResultVo> info = new PageInfo<>(list);
        return info;
    }

}